import { createRouter, createWebHistory } from 'vue-router'
// import Home_Page from '../view/Home_Page.vue'
// () => import('../view/Home_Page.vue'),
const routes = [
    {
        path: '/',
        redirect: '/Home_Page',
    },
    {
        path: '/user_page',
        name: 'user_page',
        component: () => import('../view/user_page.vue'),
    },
    {
        path: '/search_user',
        name: 'search_user',
        component: () => import('../view/search_user.vue'),
    },
    {
        path: '/post_video',
        name: 'post_video',
        component: () => import('../view/post_video.vue'),
    },
    {
        path: '/message_fan',
        name: 'message_fan',
        component: () => import('../components/message.vue/message_fan.vue'),
    },
    {
        path: '/message_comment',
        name: 'message_comment',
        component: () => import('../components/message.vue/message_comment.vue'),
    },
    {
        path: '/message_at',
        name: 'message_at',
        component: () => import('../components/message.vue/message_at.vue'),
    },
    {
        path: '/message_like',
        name: 'message_like',
        component: () => import('../components/message.vue/message_like.vue'),
    },
    {
        path: '/router_my',
        name: 'router_my',
        component: () => import('../view/router_my.vue'),
    },
    {
        path: '/Home_Page',
        name: 'Home_Page',
        component: () => import('../view/Home_Page.vue'),
        children: [
            {
                path: '/Home_Page',
                redirect: '/Home_Page-Home_video',
            },
            {
                path: '/Home_Page-Home_video',
                name: 'Home_Page-Home_video',
                component: () => import('../view/Home_video.vue'),
            },
            {
                path: '/Home_Page-Home_messge',
                name: 'Home_Page-Home_messge',
                component: () => import('../view/Home_messge.vue'),
            },
            {
                path: '/Home_Page-Home_watch',
                name: 'Home_Page-Home_watch',
                component: () => import('../view/Home_watch.vue'),
            },
            {
                path: '/Home_Page-Home_my',
                name: 'Home_Page-Home_my',
                component: () => import('../view/Home_my.vue'),
            },
        ]
    },
]

const router = createRouter({
    history: createWebHistory(),
    routes
})
router.beforeEach((to, from, next) => {
    if (from.path == '/Home_Page-Home_video' && to.path !== '/user_page') {
        if (!localStorage.getItem('user')) {
            next('/user_page')
        } else {
            next()
        }
        return
    }
    next()
})
export default router
